import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect:'/index',
      component: HomeView,
      children:[
        {
          path: '/index',
          component: () => import('../views/IndexView.vue')
        },
        {
          path: '/system/center',
          component: () => import('../views/system/MyCenterView.vue')
        },
        {
          path: '/system/dic',
          component: () => import('../views/system/DicView.vue')
        },
        {
          path: '/system/log',
          component: () => import('../views/system/LogView.vue')
        },
        {
          path: '/heart/psychometric',
          component: () => import('../views/heart/psychometric.vue')
        },
        {
          path:'/heart/question',
          component: () => import('../views/heart/question.vue')
        },
        {
          path:'/heart/reply',
          component: () => import('../views/heart/reply.vue')
        },
        {
          // 心理知识
          path: '/heart/heartknowledge',
          component: () => import('../views/heart/HeartKnowledgeView.vue')
        },
        {
          path:'/consult/consultlevel',
          name:'consultlevel',
          component:()=>import("../views/consultManagement/ConsultLevelView.vue")
        },
        {
          // 文章
        path:'/artic/article',
        component: () => import('../views/artic/ArticView.vue')
        },
        {
          // 文章类型
        path:'/artic/type',
        component: () => import('../views/artic/ArticTypeView.vue')
        },
        {
          // 公益中心
          path:'/artic/free',
          component: () => import('../views/artic/FreeView.vue')
        },
        {
          path: '/sysUserManagement',
          component: () => import('../views/sysUserManagement/sysUserManagement.vue')
        },
        {
          path:'/inquiryManagement/consulationAppointment',
          component:()=>import('../views/inquiriesOrEvaaluationsManage/consulationAppointment.vue')
        },
        {
          path:'/consulationReplyManagement',
          component:()=>import('../views/inquiriesOrEvaaluationsManage/consulationReplyManagement.vue')
        },
        {
          path:'/userFeekbackManagement',
          component:()=>import('../views/inquiriesOrEvaaluationsManage/userFeedbackManagement.vue')
        },
        {
          path:"/ConsultManagement",
          component:()=>import("../views/consultManagement/ConsultView.vue")
        },
      {
        path:"/ConsultManagement/Specilty",
        component:()=>import("../views/consultManagement/SpeciltyView.vue")
      },
      {
        path:"/ConsultManagement/changeType",
        name:"changeType",
        component:()=>import("../views/consultManagement/ChargeTypeView.vue")
      },
      {
        path:"/ConsultManagement/charge",
        name:"charge",
        component:()=>import("../views/consultManagement/ChargeView.vue")
      },
        {
          path:"/ConsultManagement/Specilty",
          component:()=>import("../views/consultManagement/SpeciltyView.vue")
        },
        // 课程管理
        {
          path: '/course/course',
          component: () => import('../views/course/CourseView.vue')
        },
        {
          path: '/course/coursetype',
          component: () => import('../views/course/CourseTypeView.vue')
        },
        { 
          // fm 动态音频
          path:'/course/fm',
          component:()=>import("../views/course/FmView.vue")
        },
        {
         path:'/UserManagement' ,
         component:()=>import('../views/UserManagement/UserManagement.vue')
        },
        {
          path:'/publicityManagement',
          component:()=>import('../views/publicityManagement/publicityManagement.vue')
        },
        {
          path:'/CompanyManagement',
          component:()=>import('../views/CompanyManagement/CompanyManagement.vue')
        },
        {
          path: '/course/coursemark',
          component: () => import('../views/course/CourseMarkView.vue')
        },
        {
          path: '/course/courseorder',
          component: () => import('../views/course/CourseOrderVIew.vue')
        },
        {
          path: '/course/coursetalk',
          component: () => import('../views/course/CourseTalkView.vue')
        },
        {
          path: '/course/coursereply',
          component: () => import('../views/course/CourseReplyView.vue')
        },
      ]
    },
    {
      path: '/login',
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/registration',
      component: () => import('../views/Registration.vue')
    },
  ],
})

// 路由守卫
router.beforeEach((to,from,next)=>{
  if(to.path === '/login' || to.path === '/registration'){
    next()
  }else{
    const token = localStorage.getItem('token')
    if(token){
      next()
    }else{
      next('/login')
    }
  }
})

export default router
